﻿using MongoDB.Bson.Serialization.Attributes;
#if !SERVER
using UnityEngine;
#endif

namespace ETModel {
    /// <summary>
    /// 额外带有ID的组件
    /// </summary>
    [BsonIgnoreExtraElements]
    public abstract class ComponentWithId : Component {
        /// <summary>
        /// 逻辑ID,由业务逻辑自行定义,需要唯一,默认使用实例ID
        /// </summary>
        [BsonIgnoreIfDefault]
        [BsonDefaultValue(0L)]
        [BsonElement]
        [BsonId]
        public long Id { get; set; }

        protected ComponentWithId() {
            this.Id = this.InstanceId;
        }

        protected ComponentWithId(long id) {
            this.Id = id;
        }

        public override void Dispose() {
            if (this.IsDisposed) {
                return;
            }

            base.Dispose();
        }
    }
}